package com.so206.security;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * 工具类
 */
public class SocketUtils {


    /**
     * 加密消息
     */
    public static String encode_message(String msg) throws Exception {
        return AESOperator.getInstance().encrypt(msg);
    }

    /**
     * 解密消息
     */
    public static String dencode_message(String msg) {
        return AESOperator.getInstance().decrypt(msg);
    }

    /**
     * 判断 ip  port  是否可连接
     */
    public static boolean isHostConnectable(String host, int port) {
        Socket socket = new Socket();
        try {
            socket.connect(new InetSocketAddress(host, port));
        } catch (IOException e) {
            return false;
        } finally {
            try {
                socket.close();
            } catch (IOException e) {
            }
        }
        return true;
    }

}
